const Utils = require('./Utils.js')

Utils.init()

var flag, region, num

num = 0
flag = true
region = [320, 80, 490, 410]

while (flag) {
    Utils.sleeps()
    if (Utils.findPictureTap('勋章空', region) || Utils.findPictureTap('勋章实', region)) {
        log('点击结界 - 成功')
        let flagTempTwo = true
        while (flagTempTwo) {
            if (Utils.findPictureTap('进攻', 0.8)) {
                Utils.sleeps()
                if (Utils.findPicture('进攻', 0.8)) {
                    click(random(150, 290), random(120, 230))
                    log('等待恢复中…………')
                    Utils.ranWaitTime(100, 120)
                } else {
                    let seconds = random(20, 30)
                    Utils.waitTime(seconds)
                    let times = 0
                    let flagTempOne = true
                    while (flagTempOne) {
                        if (Utils.tapPicture('奖励')) {
                            flagTempOne = false
                        } else if (Utils.findPictureTap('失败')) {
                            log('结界突破 - 失败')
                            flagTempOne = false
                        }
                        times++
                        log('已等待：' + (seconds + times) + '秒')
                    }
                }
                num = 0
                flagTempTwo = false
            }
        }
    }
    num++
    log('检测待突破结界第 ' + num + ' 次')
    if (num === 3) {
        let swipeTimes = 0
        let flagTempThree = true
        while (flagTempThree && swipeTimes<3) {
            swipe(random(320, 800), 105, random(320, 800), 485, 1800)
            Utils.sleeps()
            if (Utils.findPicture('勋章空', region) || Utils.findPicture('勋章实', region)) flagTempThree = false
            else swipeTimes++
        }
    }
    num === 5 ? (log('结界突破 - 完成'), Utils.stopJB()) : ''
}
